<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script type="text/javascript" src="./script/aui-sharebox.js" ></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>权限提升</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>

    <div class="index-box-bg" style="display: none;" id="alert_box">
        <div class="index-box">
            <h3 id="box_title">您已到达升级条件，请联系工作人员！</h3>
            <div class="index-box-btn" tapmode onclick="hide_method()">
                <div>知道了</div>
            </div>
        </div>
    </div>


    <div class="uplevel-examine-details-t">
        <dl>
            <dt><img id="avatar" src="image/gril.png"><p id="name">张春华</p></dt>
            <dd>申请成为<span id="level_str">金领</span>经销商</dd>
            <!-- <dd>您批准后,</dd> -->
            <!-- <dd>将从您的赚石中扣除<i id="level_integral">18000</i></dd> -->
        </dl>
        <p>
            您当前赚石
            <span id="integral">0</span>
        </p>
    </div>

    <div class="btn-1 mt60" onclick="agreeAuditing();">同意提升</div>
    <div class="btn-1 mt20" style="display: none; text-align: center;" id="refuseBtn"  onclick="refuseAuditing();">拒绝申请</div>
    <div class="btn-1 mt20" onclick="handOver();">交给上级</div>
    
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){
        name = api.pageParam.name;
        level_str = api.pageParam.level_str;
        level_integral = api.pageParam.level_integral;
        id = api.pageParam.id;
        avatar = api.pageParam.avatar;

        $('#avatar').attr('src',avatar);
        $('#name').html(name);
        $('#level_str').html(level_str);
        $('#level_integral').html(level_integral);

        getInviteCode();
    }
    
    // 获取当前用户赚石
    function getInviteCode(){
        integral = '';
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/auth/info',
            method: 'get',
            data: {
                values: {
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                integral = ret.data.integral;
                $('#integral').html(integral);
                level = ret.data.level;
                if (level == 4) {
                    $('#refuseBtn').css('display', 'flex');
                }
            } else {
                // alert( JSON.stringify( err ) );
                return false;
            }
        });
    }

    // 同意升级
    function agreeAuditing() {
        // api.openWin({
        //     name: 'uplevel_password',
        //     url: './uplevel_password.html',
        //     pageParam: {
        //         id: id,
        //         level_integral: level_integral,
        //         integral: integral,
        //     }
        // });

        api.confirm({
            title: '提示',
            msg: '是否同意升级?',
            buttons: ['确定', '取消']
        }, function(ret, err){
            if( ret ){
               // alert( JSON.stringify( ret ) );
               if (ret.buttonIndex == 1) {

                var token = $api.getStorage('token');
                api.ajax({
                    url: webAddress + '/api/user/upgrade/approval/up',
                    method: 'post',
                    data: {
                        values: { 
                          // password: password,
                          id: id,
                      },
                  },
                  headers: {
                    Authorization: 'Bearer ' + token,
                    Accept: 'application/json',
                },
            },function(ret, err){
                if (ret) {
                   // alert( JSON.stringify( ret ) );
                   api.openWin({
                    name: 'uplevel_success',
                    url: './uplevel_success.html',
                    pageParam:{
                    }
                });

               } else {
                   // alert( JSON.stringify( err ) );
                   if (err.body.status_code == 400) {

                    $api.byId('alert_box').style.display = "block";
                    $('#box_title').html(err.body.message);
                    return false;
                }
            }
        });
            }
        }else{
           // alert( JSON.stringify( err ) );
       }
   });



    }

    // 拒绝申请
    function  refuseAuditing() {

        api.confirm({
            title: '提示',
            msg: '是否拒绝审批?',
            buttons: ['确定', '取消']
        }, function(ret, err){
            if( ret ){
                // alert( JSON.stringify( ret ) );
                if (ret.buttonIndex == 1) {

                    var token = $api.getStorage('token');
                    api.ajax({
                        url: webAddress + '/api/user/upgrade/approval/closed',
                        method: 'post',
                        data: {
                            values: {
                                id: id,
                            },
                        },
                        headers: {
                            Authorization: 'Bearer ' + token,
                            Accept: 'application/json',
                        },
                    },function(ret, err){
                        if (ret) {
                            // alert( JSON.stringify( ret ) );
                            if (ret.status_code == 200) {
                                $api.byId('alert_box').style.display = "block";
                                $('#box_title').html('成功拒绝审批');
                            }
                        } else {
                            // alert( JSON.stringify( err ) );
                            if (err.body.status_code == 400) {
                                api.toast({
                                    msg: err.body.message,
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                return false;
                            }
                        }
                    });
                }
            }else{
             // alert( JSON.stringify( err ) );
         }
     });

    }

    // 交给上级
    function handOver(){
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/user/upgrade/approval/transfer',
            method: 'post',
            data: {
                values: {
                    id: id,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                if (ret.status_code == 200) {
                    $api.byId('alert_box').style.display = "block";
                    $('#box_title').html('已经转给上级审批');
                }
            } else {
                // alert( JSON.stringify( err ) );
                if (err.body.status_code == 400) {
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                    return false;
                }
            }
        });
    }

    // 关闭升级提示框
    function hide_method(){
        $api.byId('alert_box').style.display = "none";
        api.sendEvent({
          name: 'reload'
      });
        api.closeWin();
    }


    function user_wallet() {
        api.openWin({
            name: 'user_wallet',
            url: './user_wallet.html',
        });
    }
    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>